#!/bin/bash
if [ `arch` == "aarch64" ];then
        ARCH=arm64
elif [ `arch` == "x86_64" ];then
        ARCH=amd64
elif [ `arch` == "mips64" ];then
        ARCH=mips64
elif [ `arch` == "sw_64" ];then
        ARCH=sw64
else
        echo "unknow arch!!!!!"
        exit 1
fi

shopt -s extglob

if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
    DIRTY="-dirty"
fi

COMMIT=$(git rev-parse --short HEAD)
COMMIT_DATE=$(git --no-pager log -1 --format='%ct')
COMMIT_BRANCH=$(git rev-parse --abbrev-ref HEAD | sed -E 's/[^a-zA-Z0-9]+/-/g')
GIT_TAG=${DRONE_TAG:-$(git tag -l --contains HEAD | head -n 1)}
LAST_TAG=${GIT_TAG:-'v0.0.0'}

VERSION=v2.4.7
CHART_VERSION=v2.4.7

# Drop the v prefix for Chart Version to follow existing pattern.
CHART_VERSION="$(echo ${CHART_VERSION} | sed -E 's/^v//' | sed -e 's/^\(.\{55\}\).*/\1/')"

# Chart Repo - Target Repo for releases.
case $CHART_VERSION in
    *-alpha*) # All alpha tags
        CHART_REPO="alpha" ;;
    *-rc*) # All rc tags
        CHART_REPO="latest" ;;
    +([0-9]).+([0-9]).+([0-9])) # All release tags
        CHART_REPO="latest" ;;
    *) # Anything else - Future use
        CHART_REPO="dev" ;;
esac

echo "ARCH: $ARCH"
echo "CHART_REPO: $CHART_REPO"
echo "CHART_VERSION: $CHART_VERSION"
echo "VERSION: $VERSION"
